<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

include('templates/header.html');

include('../mysql_connect.php');

if (isset($_GET['random'])) {
    $query = "select quote_id, quote, source, favorite from quotes order by rand() desc limit 1";
}
elseif (isset ($_GET['favorite'])) {
    $query = "select quote_id, quote, source, favorite from quotes where favorite=1 order by rand() desc limit 1";
}
else {
    $query = "select quote_id, quote, source, favorite from quotes order by date_entered desc limit 1";
}

$r = mysql_query($query, $dbc);
if ($r) {
    $row = mysql_fetch_array($r);
    print "<div><blockquote>{$row['quote']}</blockquote>- {$row['source']}\n";
    if ($row['favorite'] == 1) {
        print '<strong>Favorite!</strong>';
    }
         
    print '</div>';
    if (is_administrator()) { 
        print "<p><b>Quote Admin:</b><a href=\"edit_quote.php?id={$row['quote_id']}\">Edit</a>
                 <a href=\"delete_quote.php?id={$row['quote_id']}\">Delete</a></p></div>\n";
    }
}
else {
    print '<p class="error">Could not retrieve the data because:<br/>' . 
            mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}

mysql_close($dbc);

print '<p><a href="index.php">Latest</a>
       <a href="index.php?random=true">Random</a>
       <a href="index.php?favorite=true">Favorite</a></p>';

include('templates/footer.html');
?>
